<%--
  Created by IntelliJ IDEA.
  User: kurong
  Date: 2021/10/13
  Time: 18:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link href="${pageContext.request.contextPath}/css/register.css" rel="stylesheet">


</head>
<body>

<div class="top">
    <div class="tips-inner">
        <a href=""><img src="${pageContext.request.contextPath}/images/logo.png"></a>
        <div class="logo-title">欢迎注册</div>

        <div class="top-login">
            已有账号?
            <a href="login.jsp">请登录></a>
        </div>
    </div>
</div>

<div class="regist-wrap">

    <form class="registForm " action="${pageContext.request.contextPath}/register" method="post">
        <ul>
            <li>
                <label class="country">&nbsp中国 +86</label>
                <txt style="position: absolute; z-index: 2; line-height: 46px; margin-left: 20px; margin-top: 1px; font-size: 14px; font-family: Arial; color: rgb(204, 204, 204); display: inline;">
                    输入常用手机号
                </txt>
                <input type="text" class="tel" name="custTelno">
                <span class="tel_msg"></span>
            </li>
            <li>
                <label>&nbsp密&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码</label>
                <txt style="position: absolute; z-index: 2; line-height: 46px; margin-left: 20px; margin-top: 1px; font-size: 14px; font-family: Arial; color: rgb(204, 204, 204); display: inline;">
                    建议使用两种或两种以上字符组合
                </txt>
                <input type="password" class="password" name="custPassword">
                <span class="password_msg"></span>
            </li>
            <li>
                <label>&nbsp确认密码</label>
                <txt style="position: absolute; z-index: 2; line-height: 46px; margin-left: 20px; margin-top: 1px; font-size: 14px; font-family: Arial; color: rgb(204, 204, 204); display: inline;">
                    请确认密码
                </txt>
                <input type="password" class="repassword">
                <span class="repassword_msg"> </span>
            </li>
            <!--            <li>-->
            <!--                <label>性别：</label>-->
            <!--                <input type="radio" name="gender" class="gender" value="M" checked> 男-->
            <!--                <input type="radio" name="gender" class="gender" value="F"> 女-->
            <!--            </li>-->
            <li>
                <label>&nbsp邮&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp箱</label>
                <txt style="position: absolute; z-index: 2; line-height: 46px; margin-left: 20px; margin-top: 1px; font-size: 14px; font-family: Arial; color: rgb(204, 204, 204); display: inline;">
                    输入常用邮箱
                </txt>

                <input type="text" class="email" name="custEmail">
                <span class="email_msg"></span>
            </li>

            <li id="telCode">
                <label>&nbsp手机验证码</label>
                <txt style="position: absolute; z-index: 2; line-height: 46px; margin-left: 20px; margin-top: 1px; font-size: 14px; font-family: Arial; color: rgb(204, 204, 204); display: inline;">
                    输入验证码
                </txt>
                <input type="text" class="code" id="code">
                <button id="getCode" class="getCode">获取验证码</button>
                <span class="code_msg"></span>

            </li>

            <li id="registForm">
                <input class="submit" type="button">注&nbsp&nbsp&nbsp&nbsp&nbsp册
            </li>

        </ul>
    </form>

<%--    <input type="button" value="密码" id="pass">--%>
</div>


<script src="${pageContext.request.contextPath}/js/register.js"></script>
<%--<script src="https://cdn.bootcss.com/jsencrypt/3.0.0-beta.1/jsencrypt.js"></script>--%>
<script src="${pageContext.request.contextPath}/res/jquery/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/res/jsencrypt/bin/jsencrypt.min.js"></script>

<script>

    var PUBLIC_KEY = '';


    $(".submit").click(function () {


        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/publickey",
            dataType: 'json',
            success: function (result) {
                PUBLIC_KEY = result.data; //获取公钥

                var encrypt = new JSEncrypt();
                encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');

                var password = $(".password").val();

                var encrypted = encrypt.encrypt(password);
                console.log('公钥:%o', PUBLIC_KEY);
                console.log('加密后数据:%o', encrypted);


                if(checkTel() && checkEmail() && checkPassword() && checkCode() && checkRePassword()){
                    // $(".password").val(encrypted);
                    $(".password").val(encrypted);
                    $(".registForm").submit();
                }

            }
        });
    });


</script>

</body>
</html>